//
//  HotLiverTableViewCell.m
//  Bread-Live
//
//  Created by ios on 2017/3/14.
//  Copyright © 2017年 Chris. All rights reserved.
//

#import "HotLiverTableViewCell.h"
#import "LiveTimeView.h"

@interface HotLiverTableViewCell ()
@property(nonatomic,strong) UIImageView  *headImgView;
@property(nonatomic,strong) UILabel      *nameLabel;
@property(nonatomic,strong) UILabel      *descritionLabel;
@property(nonatomic,strong) UIButton     *followBtn;
@property(nonatomic,strong) LiveTimeView *liveTimeView;

@end

@implementation HotLiverTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self configView];
        
    }
    return self;
}

-(void)configView{
    CGFloat viewW = self.frame.size.width;
    //CGFloat viewH = self.frame.size.height;
    
    _headImgView  = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 80, 80)];
    _headImgView.layer.cornerRadius = 6.0;
    _headImgView.layer.masksToBounds = YES;
    
    [self.contentView addSubview:_headImgView];
    
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, 150, 21)];
    _nameLabel.font       = [UIFont wyBlodFont:16];
    _nameLabel.textColor  = WYCOLOR(86, 86, 86, 1.0);
    
    [self.contentView addSubview:_nameLabel];
    
    _descritionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 45, kWidth-100-50, 21)];
    _descritionLabel.font       = [UIFont wyNormalFot:13];
    _descritionLabel.textColor  = WYCOLOR(140, 140, 140, 1.0);
    
    [self.contentView addSubview:_descritionLabel];
    
    _liveTimeView = [[LiveTimeView alloc] init];
    
    [self.contentView addSubview:_liveTimeView];
    
    _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _followBtn.frame = CGRectMake(viewW - 60, 15, 50, 20);
    
    [_followBtn setTitle:@"关注" forState:UIControlStateNormal];
    [_followBtn setTitle:@"已关注" forState:UIControlStateSelected];
    [_followBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    
    _followBtn.titleLabel.font = [UIFont wyNormalFot:13];
    
    _followBtn.layer.cornerRadius = 6.0;
    _followBtn.layer.borderColor  = [UIColor blackColor].CGColor;
    _followBtn.layer.borderWidth  = 1.0;
    [_followBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:_followBtn];
    
}


-(void)btnClick:(UIButton *)sender{
    
    sender.selected = !sender.selected;
    if (sender.selected) {
        
        [sender setBackgroundColor:WYCOLOR(191, 190, 191, 1.0)];
        sender.layer.borderColor = [UIColor clearColor].CGColor;
    }else{
        
        [sender setBackgroundColor:[UIColor whiteColor]];
        sender.layer.borderColor = [UIColor blackColor].CGColor;
    }
    
#warning    通过代理 block 等方式 将数据源信息修改
    
    
    
}


-(void)setModel:(HotLiverModel *)model{
    
    [_headImgView sd_setImageWithURL:[NSURL URLWithString:model.headImgUrl]];
    
    _nameLabel.text       = model.name;
    
    _descritionLabel.text = model.descritionText;
    
    _followBtn.selected   = model.isfollow;
    
    if (_followBtn.selected) {
        [_followBtn setBackgroundColor:WYCOLOR(191, 190, 191, 1.0)];
        _followBtn.layer.borderColor  = [UIColor clearColor].CGColor;
    }else{
        [_followBtn setBackgroundColor:[UIColor whiteColor]];
         _followBtn.layer.borderColor = [UIColor blackColor].CGColor;
    }
    
    
    CGFloat width = [ToolsCustom setLabelText:model.time textFont:[UIFont wyNormalFot:13]];
    
    _liveTimeView.frame = CGRectMake(100, 75, width+25, 25);
    
    [_liveTimeView setliveTimeTitle:model.time liveStatus:_followBtn.selected];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
